﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public delegate void SignalDelegate(params object[] args);
    public sealed class SignalEvent
    {
        private LinkedList<SignalDelegate> signalevelist;
        public void Clear()
        {
            if (this.signalevelist != null)
            {
                this.signalevelist.Clear();
            }
        }
        public SignalHandle Create(SignalDelegate _event)
        {
            if (this.signalevelist == null)
            {
                this.signalevelist = new LinkedList<SignalDelegate>();
            }
            LinkedListNode<SignalDelegate> linkedListNode = this.signalevelist.AddLast(_event);
            return new SignalHandle(this.signalevelist, linkedListNode);
        }

        public void Excute(params object[] args)
        {
            if (this.signalevelist != null)
            {
                LinkedListNode<SignalDelegate> next;
                for (LinkedListNode<SignalDelegate> linkedListNode = this.signalevelist.First; linkedListNode != null; linkedListNode = next)
                {
                    next = linkedListNode.Next;
                    SignalDelegate _event = linkedListNode.Value;
                    _event(args);
                }
            }
        }


    }
}

